<?

include "../config/constants.php";

mysql_connect("localhost", "canss", "1022") or die("Could not connect: " . mysql_error());
mysql_select_db("rule_db");

$RuleName 	= $_POST[RuleName];
$Desc		= $_POST[Description];
$XSL 		= $_POST[XSL];
$MAP		= $_POST[MAP];
$CPID		= $_POST[CPID];
$FEED		= $_POST[FEED];
$NMS 		= $_POST[NMS];
$EncType	= $_POST[ENC];

$RID = md5( $CPID.$FEED );

$query = "
INSERT INTO `rule_db`.`rule` (
`rid` ,
`namespaces`,
`map` ,
`XSL` ,
`rname`,
`rdesc`,
`encType` 
)
VALUES (
'$RID', '$NMS', '$MAP', '$XSL', '$RuleName', '$Desc', '$EncType'
);";

if( !mysql_query($query) ){
	echo "Already Rule is Exist, try to modify...\n";

	$query = "
	UPDATE `rule_db`.`rule` SET 
	`namespaces`='$NMS',
	`map`='$MAP',
	`XSL`='$XSL',
	`rname`='$RuleName',
	`rdesc`='$Desc',
	`encType`='$EncType'
	WHERE `rid`='$RID'";

	if( !mysql_query($query) ){
		echo "ERROR ".$query;
		exit;
	}

}

$wsclient = new SoapClient(WS_PORTAL);
$wsclient->setFeedRulesByPIDURI( array('_pid'=>$CPID, '_uri'=>$FEED, '_ruleid'=>$RID) );

echo $RuleName." is saved";

?>
